﻿#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

#include <QtMath>


#include "fftw3.h"
int Widget::fft_testIN()
{
#if 1
    int N = 151;
    fftw_complex *in, *out;
    fftw_plan p;
    //add code;
    in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
    out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
    p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
    //add code;
    for (int i = 0; i < N; i++)
    {
        in[i][0] =100* qAsin(i);//real
        in[i][1] = i;//image
    }
    fftw_execute(p); /* repeat as needed */
    //add code;
    for (int i = 0; i < N; i++)
    {
        qDebug()<<i;
        qDebug()<<out[i][0]<<","<<out[i][1];
    }
    fftw_destroy_plan(p);
    fftw_free(in); fftw_free(out);
#endif
    qDebug()<<"bye";
    return 0;
}



void Widget::on_pushButtonStart_clicked()
{
        fft_testIN();
}

